﻿using Autodesk.AutoCAD.DatabaseServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YZQ_DotNetArx.CAD
{
    public static class DimStyleTools
    {
        /// <summary>
        /// 创建一个新的标注样式
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="styleName">标注样式名</param>
        /// <returns>返回新建的标注样式的Id</returns>
        public static ObjectId AddDimStyle(this Database db, string styleName)
        {
            //打开标注样式表
            DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead);
            if (!dst.Has(styleName)) //如果不存在名为styleName的标注样式，则新建一个标注样式
            {
                //定义一个新的标注样式表记录
                DimStyleTableRecord dstr = new DimStyleTableRecord();
                dstr.Name = styleName; //设置标注样式名
                dst.UpgradeOpen();
                //把标注样式表记录添加到事务处理中
                db.TransactionManager.AddNewlyCreatedDBObject(dstr,true);
                dst.DowngradeOpen();
            }
            return dst[styleName];
        }
    }
}
